import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import {  ActionSheetConfig } from 'ngx-weui';
import { ApiService } from 'src/app/core/api';
import { Global } from 'src/app/core/global';
import { StorageService } from 'src/app/core/sotrage/storage.service';
import { GB } from '../../../environments/environment';
import { I18nService } from '../../core/i18n/i18n.service';

@Component({
	templateUrl: './index.component.html',
	styleUrls: ['./index.less'],
})
export class BankComponent implements OnInit {
	isEmail = true;
	constructor(
		private i: I18nService, 
		private activedRoute: ActivatedRoute,
		private router: Router, 
		private fb: FormBuilder, 
		private api: ApiService, 
		private sto: StorageService) {
		this.i.get(['MSG.register-code', 'MSG.register-user']).subscribe(res => {
			this.msgData = res;
		});
	}
	pageType = 1;

	config: ActionSheetConfig = {
		title: 'Language changes',
	} as ActionSheetConfig;

	gb = GB;
	ob;
	res: any = {
		id: '',
		mail: '',
		mobile: '',
		vcode: '',
		password: '',
		rpassword: '',
		worldpost: '1',
	};
	registerEmailForm: FormGroup;
	e: number;
	msgData: any;
	ngOnInit() {
		this.configForm();
	}

	configForm(){
			this.registerEmailForm = this.fb.group(
				{
					agencyId: [this.sto.get('user').id, [Validators.required]],
					bankSubBranch: ['', [Validators.required]],
					bankName: ['', [Validators.required]],
					bankAccountNum: ['', [Validators.required]],
					bankAccountName: ['', [Validators.required]],
					mobile: ['', [Validators.required]]
				}
			);
	
			this.registerEmailForm.setErrors({
				email: false
			});

		// }
	}

	onChangType(bool) {
		this.isEmail = bool;
		this.configForm();
	}

	onSave(f) {
		const data =f.value ;
		this.api.post('用户注册(2/2 用户银行信息)', data).then(res => {
			this.sto.set('user', res['data']);
			this.router.navigate(['/']);
		});
	}
}

